//
//  LSQueryResultsViewController.m
//  lightSpot
//
//  Created by lightSpot on 2023/10/17.
//  Copyright © 2023 lightSpot. All rights reserved.
//

#import "LSQueryResultsViewController.h"

@interface LSQueryResultsViewController ()

@end

@implementation LSQueryResultsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationItemTitleViewWithTitle:@"查询结果"];
    [self getAreaRequest];
}

#pragma 网络请求

- (void)getAreaRequest {
    [SVProgressHUD show];
    [kRequestManager getTargaRequestWithWord:_word success:^(id responseObject) {
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dic = responseObject;
            [self setData:dic];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSString *errorMsg) {
        if (![errorMsg isEqualToString:@"数据返回为空"]) {
            [self showProgressHUD:errorMsg];
        } else {
            [self showProgressHUD:@"暂无更多数据"];
        }
        [SVProgressHUD dismiss];
    }];
}

- (void)setData:(NSDictionary *)dic {
    NSString *str = @"";
    NSString *targa = dic[@"targa"];
    if (targa.length > 0) {
        str = [NSString stringWithFormat:@"%@\n",targa];
    }
    
    NSString *notes = dic[@"notes"];
    if (notes.length > 0) {
        str = [NSString stringWithFormat:@"%@%@",str,notes];
    }
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, self.navigationBarHeight + 20, kScreenWidth - 20*2, 405)];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 15;
    view.layer.masksToBounds = YES;
    [self.view addSubview:view];
    
    CGSize titleSize = [str ex_sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(kScreenWidth, MAXFLOAT)];
        
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, view.frame.size.width - 20*2, titleSize.height + 20)];
    label.text = str;
    label.textColor = UIColorFromHex(0x333333);
    label.font = [UIFont systemFontOfSize:18];
    label.textAlignment = NSTextAlignmentLeft;
    label.numberOfLines = 0;
    [view addSubview:label];
}

@end
